// pages/softStep2/softStep2.js
const util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    line1MinNum : 45,
    line1MaxNum : 75,
  
    line2MinNum : 2,
    line2MaxNum : 20,
  
    line3MinNum : 45,
    line3MaxNum : 75,
   
    line4MinNum : 2,
    line4MaxNum : 20,
    
    line5MinNum : 45,
    line5MaxNum : 75,
    
    line6MinNum : 2,
    line6MaxNum : 20,
    
    line7MinNum : 45,
    line7MaxNum : 75,
    
    line8MinNum : 2,
    line8MaxNum : 20,
    
    line9MinNum : 45,
    line9MaxNum : 75,

    line1: '',
    line1Error: false,

    line2: '',
    line2Error: false,
    line3: '',
    line3Error: false,
    line4: '',
    line4Error: false,
    line5: '',
    line5Error: false,
    line6: '',
    line6Error: false,
    line7: '',
    line7Error: false,
    line8: '',
    line8Error: false,
    line9: '',
    line9Error: false,

    title: '',
    project_id:'',

  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if (options.title){
      this.setData({
        title: options.title
      })
      
    }
    if (options.project_id){
      this.setData({
        project_id: options.project_id
      }) 
    }
    console.log(this.data.project_id)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    var pid = this.data.project_id
    var docItemKey = 'pid_'+pid
    var stableDocData = wx.getStorageSync(docItemKey)
    if(stableDocData){
        var docJson = JSON.parse(stableDocData)
        if(docJson.step2Data!==undefined && docJson.step2Data!=null){
            this.data.line1 = docJson.step2Data.line1
            this.data.line2 = docJson.step2Data.line2
            this.data.line3 = docJson.step2Data.line3
            this.data.line4 = docJson.step2Data.line4
            this.data.line5 = docJson.step2Data.line5
            this.data.line6 = docJson.step2Data.line6
            this.data.line7 = docJson.step2Data.line7
            this.data.line8 = docJson.step2Data.line8
            this.data.line9 = docJson.step2Data.line9
        }
    }
    var that = this
    this.setData(
        that.data
    )
  },

  onSave(){
    if(!util.checkInputNum('line1',this.data.line1,'范围概述',this.data.line1MinNum,this.data.line1MaxNum)){
      this.setData({line1Error: true})
      return;
    }else{
      this.setData({line1Error: false})
    }
    if(!util.checkInputNum('line2',this.data.line2,'模块1标题',this.data.line2MinNum,this.data.line2MaxNum)){
      this.setData({line2Error: true})
      return;
    }else{
      this.setData({line2Error: false})
    }
    if(!util.checkInputNum('line3',this.data.line3,'模块1概述',this.data.line3MinNum,this.data.line3MaxNum)){
      this.setData({line3Error: true})
      return;
    }else{
      this.setData({line3Error: false})
    }
    if(!util.checkInputNum('line4',this.data.line4,'模块2标题',this.data.line4MinNum,this.data.line4MaxNum)){
      this.setData({line4Error: true})
      return;
    }else{
      this.setData({line4Error: false})
    }
    if(!util.checkInputNum('line5',this.data.line5,'模块2概述',this.data.line5MinNum,this.data.line5MaxNum)){
      this.setData({line5Error: true})
      return;
    }else{
      this.setData({line5Error: false})
    }
    if(!util.checkInputNum('line6',this.data.line6,'模块3标题',this.data.line6MinNum,this.data.line6MaxNum)){
      this.setData({line6Error: true})
      return;
    }else{
      this.setData({line6Error: false})
    }
    if(!util.checkInputNum('line7',this.data.line7,'模块3概述',this.data.line7MinNum,this.data.line7MaxNum)){
      this.setData({line7Error: true})
      return;
    }else{
      this.setData({line7Error: false})
    }
    if(!util.checkInputNum('line8',this.data.line8,'模块4标题',this.data.line8MinNum,this.data.line8MaxNum)){
      this.setData({line8Error: true})
      return;
    }else{
      this.setData({line8Error: false})
    }
    if(!util.checkInputNum('line9',this.data.line9,'模块4概述',this.data.line9MinNum,this.data.line9MaxNum)){
      this.setData({line9Error: true})
      return;
    }else{
      this.setData({line9Error: false})
    }

    var nowData = {}
    nowData.line1 = this.data.line1
    nowData.line2 = this.data.line2
    nowData.line3 = this.data.line3
    nowData.line4 = this.data.line4
    nowData.line5 = this.data.line5
    nowData.line6 = this.data.line6
    nowData.line7 = this.data.line7
    nowData.line8 = this.data.line8
    nowData.line9 = this.data.line9

    var pid = this.data.project_id
    var itemKey = 'pid_'+pid
    var value = wx.getStorageSync(itemKey)
    var docJson = JSON.parse(value)
    docJson.step2Data = nowData
    wx.setStorageSync(itemKey,JSON.stringify(docJson))
    wx.navigateBack()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  bindInput1(e){
    this.setData({
      line1: e.detail.value
    });
    console.log(e.detail.value)
  },
  bindInput2(e){
    this.setData({
      line2: e.detail.value
    });
    console.log(e.detail.value)
  },
  bindInput3(e){
    this.setData({
      line3: e.detail.value
    });
    console.log(e.detail.value)
  },
  bindInput4(e){
    this.setData({
      line4: e.detail.value
    });
    console.log(e.detail.value)
  },
  bindInput5(e){
    this.setData({
      line5: e.detail.value
    });
    console.log(e.detail.value)
  },
  bindInput6(e){
    this.setData({
      line6: e.detail.value
    });
    console.log(e.detail.value)
  },
  bindInput7(e){
    this.setData({
      line7: e.detail.value
    });
    console.log(e.detail.value)
  },
  bindInput8(e){
    this.setData({
      line8: e.detail.value
    });
    console.log(e.detail.value)
  },
  bindInput9(e){
    this.setData({
      line9: e.detail.value
    });
    console.log(e.detail.value)
  },

  
})